/* Nate Deisinger (ndeisinger@wisc.edu)
 *
 * This file is part of soot-csi, a project to apply lightweight
 * instrumentation to Java programs to facilitate debugging through
 * the Soot analysis framework.
 *
 * Copyright (c) 2014, Nate Deisinger, University of Wisconsin-Madison
 *   Madison, Wisconsin 53715
 *   All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor,
 *   Boston, MA  02110-1301
 *   USA
 * or retrieve version 2.1 at their website:
 *   http://www.gnu.org/licenses/lgpl-2.1.html
 */
package uwmadison.jpdg;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.gson.Gson;

import edu.cwru.jpdg.graph.Edge;
import edu.cwru.jpdg.graph.Graph;

import soot.jimple.DefinitionStmt;

/**
 * A partial implementation of an extension to the JavaPDG project to
 * allow for exporting graphs in a GraphML-friendly format.
 * 
 * Requires the JPDG classes to build.  (https://github.com/timtadh/jpdg)
 * @author Nate Deisinger
 */
public class ExtendedDataEdge extends Edge {
    
    DefinitionStmt d_stmt;

    public ExtendedDataEdge(int src, int targ, String label, Graph g) {
        super(src, targ, label, g);
    }

    public ExtendedDataEdge(int src, int targ, String label, Graph g, DefinitionStmt d_stmt) {
        super(src, targ, label, g);
        this.d_stmt = d_stmt;
    }
    
    public String Serialize()
    {
        Map<String,Object> M = new LinkedHashMap<String,Object>();
        M.put("src", ExtendedDataNode.IDMap.get(src));
        M.put("targ", ExtendedDataNode.IDMap.get(targ));
        M.put("label", label.equals("cdg") ? "control" : "data");
        //M.put("src_label", g.label(src));
        //M.put("targ_label", g.label(targ));
        //M.put("d_stmt", d_stmt.getLeftOp().toString());
        return "edge\t" + (new Gson()).toJson(M);    
    }
}
